var AgentIface = loadInterfaceXML('org.freedesktop.GeoClue2.Agent');
-var Indicator = GObject.registerClass(
-class Indicator extends PanelMenu.SystemIndicator {
+var Indicator = GObject.registerClass({
+ Properties: {
+ 'enabled': GObject.ParamSpec.boolean(
+ 'enabled', 'Enabled', 'Enabled',
+ GObject.ParamFlags.READWRITE,
+ false),
+ 'in-use': GObject.ParamSpec.boolean(
+ 'in-use', 'In use', 'In use',
+ GObject.ParamFlags.READABLE,
+ false),
+ 'max-accuracy-level': GObject.ParamSpec.int(
+ 'max-accuracy-level', 'Max accuracy level', 'Max accuracy level',
+ GObject.ParamFlags.READABLE,
+ 0, 8, 0),
+ },
+}, class Indicator extends PanelMenu.SystemIndicator {
_init() {
super._init();
this._settings = new Gio.Settings({ schema_id: LOCATION_SCHEMA });
this._settings.connect('changed::%s'.format(ENABLED),
- this._onMaxAccuracyLevelChanged.bind(this));
+ () => this.notify('enabled'));
this._settings.connect('changed::%s'.format(MAX_ACCURACY_LEVEL),
- this._onMaxAccuracyLevelChanged.bind(this));
+ this._onMaxAccuracyLevelChanged.bind(this));
this._indicator = this._addIndicator();
this._indicator.icon_name = 'find-location-symbolic';
+ this.bind_property('in-use', this._indicator, 'visible', GObject.BindingFlags.SYNC_CREATE);
this._item = new PopupMenu.PopupSubMenuMenuItem('', true);
this._item.icon.icon_name = 'find-location-symbolic';
+ this.bind_property('in-use', this._item, 'visible', GObject.BindingFlags.SYNC_CREATE);
this._agent = Gio.DBusExportedObject.wrapJSObject(AgentIface, this);
this._agent.export(Gio.DBus.system, '/org/freedesktop/GeoClue2/Agent');
this.menu.addMenuItem(this._item);
+ this.connect('notify::enabled', this._onMaxAccuracyLevelChanged.bind(this));
+ this.connect('notify::in-use', this._updateMenuLabels.bind(this));
+ this.connect('notify::max-accuracy-level', this._updateMenuLabels.bind(this));
+
this._watchId = Gio.bus_watch_name(Gio.BusType.SYSTEM,
'org.freedesktop.GeoClue2',
0,
this._connectToPermissionStore();
}
- get MaxAccuracyLevel() {
- return this._getMaxAccuracyLevel();
+ get enabled() {
+ return this._settings.get_boolean(ENABLED);
+ }
+
+ set enabled(value) {
+ this._settings.set_boolean(ENABLED, value);
+ }
+
+ get inUse() {
+ return this._managerProxy?.InUse ?? false;
+ }
+
+ get maxAccuracyLevel() {
+ if (this.enabled) {
+ let level = this._settings.get_string(MAX_ACCURACY_LEVEL);
+
+ return GeoclueAccuracyLevel[level.toUpperCase()] ||
+ GeoclueAccuracyLevel.NONE;
+ } else {
+ return GeoclueAccuracyLevel.NONE;
+ }
}
AuthorizeAppAsync(params, invocation) {
let [desktopId, reqAccuracyLevel] = params;
let authorizer = new AppAuthorizer(desktopId,
- reqAccuracyLevel,
- this._permStoreProxy,
- this._getMaxAccuracyLevel());
+ reqAccuracyLevel, this._permStoreProxy, this.maxAccuracyLevel);
authorizer.authorize(accuracyLevel => {
let ret = accuracyLevel != GeoclueAccuracyLevel.NONE;
});
}
- _syncIndicator() {
- if (this._managerProxy == null) {
- this._indicator.visible = false;
- this._item.visible = false;
- return;
- }
-
- this._indicator.visible = this._managerProxy.InUse;
- this._item.visible = this._indicator.visible;
- this._updateMenuLabels();
+ get MaxAccuracyLevel() {
+ return this.maxAccuracyLevel;
}
_connectToGeoclue() {
this._propertiesChangedId = this._managerProxy.connect('g-properties-changed',
this._onGeocluePropsChanged.bind(this));
- this._syncIndicator();
+ this.notify('in-use');
this._managerProxy.AddAgentRemote('gnome-shell', this._onAgentRegistered.bind(this));
}
}
this._managerProxy = null;
- this._syncIndicator();
+ this.notify('in-use');
}
_onOnOffAction() {
- let enabled = this._settings.get_boolean(ENABLED);
- this._settings.set_boolean(ENABLED, !enabled);
+ this.enabled = !this.enabled;
}
_onSessionUpdated() {
}
_updateMenuLabels() {
- if (this._settings.get_boolean(ENABLED)) {
+ if (this.enabled) {
this._item.label.text = this._indicator.visible
? _("Location In Use")
: _("Location Enabled");
}
_onMaxAccuracyLevelChanged() {
- this._updateMenuLabels();
+ this.notify('max-accuracy-level');
// Gotta ensure geoclue is up and we are registered as agent to it
// before we emit the notify for this property change.
this._notifyMaxAccuracyLevel();
}
- _getMaxAccuracyLevel() {
- if (this._settings.get_boolean(ENABLED)) {
- let level = this._settings.get_string(MAX_ACCURACY_LEVEL);
-
- return GeoclueAccuracyLevel[level.toUpperCase()] ||
- GeoclueAccuracyLevel.NONE;
- } else {
- return GeoclueAccuracyLevel.NONE;
- }
- }
-
_notifyMaxAccuracyLevel() {
- let variant = new GLib.Variant('u', this._getMaxAccuracyLevel());
+ let variant = new GLib.Variant('u', this.maxAccuracyLevel);
this._agent.emit_property_changed('MaxAccuracyLevel', variant);
}
_onGeocluePropsChanged(proxy, properties) {
let unpacked = properties.deep_unpack();
if ("InUse" in unpacked)
- this._syncIndicator();
+ this.notify('in-use');
}
_connectToPermissionStore() {